from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-11 14:12:22.626799
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 11, Aug, 2021
Time: 14:12:27
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.6150
Nobs: 380.000 HQIC: -46.1779
Log likelihood: 4081.40 FPE: 6.08701e-21
AIC: -46.5482 Det(Omega_mle): 4.81809e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.486781 0.096569 5.041 0.000
L1.Burgenland 0.100780 0.049672 2.029 0.042
L1.Kärnten -0.116807 0.024100 -4.847 0.000
L1.Niederösterreich 0.176671 0.105709 1.671 0.095
L1.Oberösterreich 0.074902 0.104489 0.717 0.473
L1.Salzburg 0.299677 0.051067 5.868 0.000
L1.Steiermark 0.014694 0.067634 0.217 0.828
L1.Tirol 0.134581 0.053535 2.514 0.012
L1.Vorarlberg -0.110881 0.048108 -2.305 0.021
L1.Wien -0.055352 0.093703 -0.591 0.555
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const -0.030209 0.232439 -0.130 0.897
L1.Burgenland -0.040851 0.119559 -0.342 0.733
L1.Kärnten 0.036038 0.058008 0.621 0.534
L1.Niederösterreich -0.201435 0.254441 -0.792 0.429
L1.Oberösterreich 0.549486 0.251504 2.185 0.029
L1.Salzburg 0.309597 0.122917 2.519 0.012
L1.Steiermark 0.105199 0.162794 0.646 0.518
L1.Tirol 0.298383 0.128858 2.316 0.021
L1.Vorarlberg -0.017453 0.115795 -0.151 0.880
L1.Wien 0.004131 0.225542 0.018 0.985
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.263792 0.049951 5.281 0.000
L1.Burgenland 0.094916 0.025693 3.694 0.000
L1.Kärnten -0.004187 0.012466 -0.336 0.737
L1.Niederösterreich 0.230993 0.054679 4.224 0.000
L1.Oberösterreich 0.152428 0.054048 2.820 0.005
L1.Salzburg 0.036956 0.026415 1.399 0.162
L1.Steiermark 0.009654 0.034985 0.276 0.783
L1.Tirol 0.077494 0.027692 2.798 0.005
L1.Vorarlberg 0.056978 0.024884 2.290 0.022
L1.Wien 0.081647 0.048469 1.685 0.092
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.196710 0.049088 4.007 0.000
L1.Burgenland 0.040377 0.025249 1.599 0.110
L1.Kärnten -0.006485 0.012250 -0.529 0.597
L1.Niederösterreich 0.131791 0.053734 2.453 0.014
L1.Oberösterreich 0.305251 0.053114 5.747 0.000
L1.Salzburg 0.102078 0.025959 3.932 0.000
L1.Steiermark 0.138004 0.034380 4.014 0.000
L1.Tirol 0.078064 0.027213 2.869 0.004
L1.Vorarlberg 0.055860 0.024454 2.284 0.022
L1.Wien -0.042776 0.047631 -0.898 0.369
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.205531 0.098068 2.096 0.036
L1.Burgenland -0.058642 0.050443 -1.163 0.245
L1.Kärnten -0.037856 0.024474 -1.547 0.122
L1.Niederösterreich 0.071636 0.107350 0.667 0.505
L1.Oberösterreich 0.197880 0.106111 1.865 0.062
L1.Salzburg 0.265957 0.051860 5.128 0.000
L1.Steiermark 0.078549 0.068684 1.144 0.253
L1.Tirol 0.124772 0.054366 2.295 0.022
L1.Vorarlberg 0.120180 0.048855 2.460 0.014
L1.Wien 0.036233 0.095157 0.381 0.703
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.035145 0.076800 0.458 0.647
L1.Burgenland 0.026431 0.039503 0.669 0.503
L1.Kärnten 0.050815 0.019166 2.651 0.008
L1.Niederösterreich 0.198191 0.084069 2.357 0.018
L1.Oberösterreich 0.341042 0.083099 4.104 0.000
L1.Salzburg 0.048713 0.040613 1.199 0.230
L1.Steiermark -0.001573 0.053789 -0.029 0.977
L1.Tirol 0.115668 0.042576 2.717 0.007
L1.Vorarlberg 0.062626 0.038260 1.637 0.102
L1.Wien 0.124116 0.074521 1.666 0.096
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.163498 0.093510 1.748 0.080
L1.Burgenland 0.024255 0.048099 0.504 0.614
L1.Kärnten -0.061112 0.023336 -2.619 0.009
L1.Niederösterreich -0.102558 0.102361 -1.002 0.316
L1.Oberösterreich 0.190480 0.101180 1.883 0.060
L1.Salzburg 0.030673 0.049450 0.620 0.535
L1.Steiermark 0.302464 0.065492 4.618 0.000
L1.Tirol 0.492476 0.051840 9.500 0.000
L1.Vorarlberg 0.066988 0.046584 1.438 0.150
L1.Wien -0.103782 0.090735 -1.144 0.253
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160617 0.101869 1.577 0.115
L1.Burgenland -0.005910 0.052398 -0.113 0.910
L1.Kärnten 0.062602 0.025422 2.462 0.014
L1.Niederösterreich 0.194187 0.111511 1.741 0.082
L1.Oberösterreich -0.127870 0.110224 -1.160 0.246
L1.Salzburg 0.246551 0.053870 4.577 0.000
L1.Steiermark 0.158528 0.071346 2.222 0.026
L1.Tirol 0.051308 0.056473 0.909 0.364
L1.Vorarlberg 0.122410 0.050748 2.412 0.016
L1.Wien 0.140771 0.098846 1.424 0.154
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.520784 0.054941 9.479 0.000
L1.Burgenland -0.023858 0.028260 -0.844 0.399
L1.Kärnten -0.009165 0.013711 -0.668 0.504
L1.Niederösterreich 0.191008 0.060141 3.176 0.001
L1.Oberösterreich 0.251730 0.059447 4.235 0.000
L1.Salzburg 0.022715 0.029054 0.782 0.434
L1.Steiermark -0.026172 0.038479 -0.680 0.496
L1.Tirol 0.073442 0.030458 2.411 0.016
L1.Vorarlberg 0.060182 0.027370 2.199 0.028
L1.Wien -0.058875 0.053311 -1.104 0.269
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.022527 0.063994 0.129779 0.121388 0.034741 0.067588 -0.003365 0.169397
Kärnten 0.022527 1.000000 -0.059208 0.129544 0.045019 0.068750 0.459181 -0.094074 0.100883
Niederösterreich 0.063994 -0.059208 1.000000 0.284737 0.089048 0.269419 0.014430 0.142782 0.255934
Oberösterreich 0.129779 0.129544 0.284737 1.000000 0.176893 0.294945 0.162548 0.119109 0.131386
Salzburg 0.121388 0.045019 0.089048 0.176893 1.000000 0.125427 0.048852 0.108708 0.051784
Steiermark 0.034741 0.068750 0.269419 0.294945 0.125427 1.000000 0.128398 0.087026 -0.025939
Tirol 0.067588 0.459181 0.014430 0.162548 0.048852 0.128398 1.000000 0.035430 0.126335
Vorarlberg -0.003365 -0.094074 0.142782 0.119109 0.108708 0.087026 0.035430 1.000000 -0.046635
Wien 0.169397 0.100883 0.255934 0.131386 0.051784 -0.025939 0.126335 -0.046635 1.000000